/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Controller;

/**
 * A subtype of he menu option class. This class is the one that controls the
 * probability of a a car entering the horizontal lanes
 * @author Luke
 */
public class UCProb_HorzCars extends UCMenuOption {

    /**
     * This method takes the user input, assesses it and either uses it
     * or dumps it.
     * @return The return is the user input or the default value.
     */
    @Override
    public Float run() {
        System.out.println(get_MenuOption()); //System asks for probability of a car enter a horizontal lane
        String userInput = theInput.nextLine(); //User enters a value for the probability
        int the_Check = checkInput(userInput); //System checks the input for validity
        if (the_Check == 0) {
            System.out.println("The input given was not a decimal, try again please."); //System informs user of bad input
            run(); //System asks user for the probability of a car entering the horizontal lane (again)
        } else if (the_Check == 1) {
            float flt_userInput = Float.valueOf(userInput.trim()).floatValue();
            if ((flt_userInput > 0 || flt_userInput == 0) && (flt_userInput < 1 || flt_userInput == 1)) { //3.	System checks the input for validity
                return (flt_userInput); //System accepts the users input for the probability of a car entering a horizontal lane
            } else {
                System.out.println("The input given was not between 0 and 1, try again please."); //System informs user of bad input
                run(); //System asks user for the probability of a car entering the horizontal lane (again)
            }

        }
        return (0.5f); //System uses the default value for the probability of a car entering the horizontal lane
    }




























    @Override
    public int checkInput(String someInput) {
        try {
            Float.valueOf(someInput.trim()).floatValue();
            return 1;
        } catch (Exception e) {
            return 0;
        }
    }
}
